package com.example.luozizhao.eprxdemo.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.telephony.TelephonyManager;

import com.example.luozizhao.eprxdemo.commom.App;

/**
 * @creation 2015-5-15 下午5:49:30
 * @instruction App相关辅助类
 */
public class AppPhoneUtils  
{  
 
   private AppPhoneUtils()  
   {  
       /* cannot be instantiated */  
       throw new UnsupportedOperationException("cannot be instantiated");
 
   }  
 
   /** 
    * 获取应用程序名称 
    */  
   public static String getAppName()
   {  
       try  
       {  
           PackageManager packageManager = App.applicationContext.getPackageManager();
           PackageInfo packageInfo = packageManager.getPackageInfo(
                   App.applicationContext.getPackageName(), 0);
           int labelRes = packageInfo.applicationInfo.labelRes;  
           return App.applicationContext.getResources().getString(labelRes);
       } catch (NameNotFoundException e)
       {  
           e.printStackTrace();  
       }  
       return "";  
   }  
 
   /** 
    * [获取应用程序版本名称信息] 
    *  
    * @param context 
    * @return 当前应用的版本名称 
    */  
   public static String getVersionName()
   {  
       try  
       {  
           PackageManager packageManager = App.applicationContext.getPackageManager();
           PackageInfo packageInfo = packageManager.getPackageInfo(
                   App.applicationContext.getPackageName(), 0);
           return packageInfo.versionName;  
 
       } catch (NameNotFoundException e)
       {  
           e.printStackTrace();  
       }  
       return null;  
   }  
 
   /**
    * 获取手机的 IMIE
    * @return
    */
   public static String getIMIE(){
	   TelephonyManager TelephonyMgr = (TelephonyManager)App.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
	   String szImei = TelephonyMgr.getDeviceId();
	   if(null==szImei) 
		   szImei = "0000000000000";
	   return szImei;
   }
   /**
    * 获取手机的 IMSI
    * @return
    */
   public static String getIMSI(){
	   TelephonyManager TelephonyMgr = (TelephonyManager)App.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
	   String imsi = TelephonyMgr.getSubscriberId();
	   if(null==imsi) 
		   imsi = "0000000000000";
	   return imsi;
   }
   
   /**
    * 获取硬件手机号码
    */
   public static String getDevPhoneNumber(){
	   TelephonyManager TelephonyMgr = (TelephonyManager)App.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
	   String number = TelephonyMgr.getLine1Number();
//	   if(null==number) 
//		   number = "00000000000";
	   return number;
   }
   
}  